package jzoffer;

import java.util.Stack;

/**
 * @author MaoLin Wang
 * @date 2020/10/9 11:39 下午
 */
public class _31栈的压入压出 {
    public static boolean validateStackSequences(int[] pushed, int[] popped) {
        Stack<Integer>stack=new Stack<>();
        int index=0;
        for (int i = 0; i < pushed.length; i++) {
            stack.push(pushed[i]);
            while (!stack.isEmpty() && stack.peek()== popped[index]){
                stack.pop();
                index++;
            }
        }
        return stack.isEmpty();
    }
}
